package com.xonro.common.histrans.sfeg.job.update.contarct;

import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.schedule.IJob;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.xonro.common.histrans.base.consts.SfegConst;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.List;

public class UpdateAContractNo implements IJob {


    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        SDK.getLogAPI().consoleInfo("开始处理A.B类合同签订申请日期问题");
        List<RowMap> maps = DBSql.getMaps("SELECT ID,CONTRACT_NO  FROM BO_XR_EPM_A_CONTRACT  ");

        for(RowMap m:maps){
            String contractNo=m.getString("CONTRACT_NO");
            String id=m.getString("ID");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMap("SELECT fillDate,ctCode FROM tb_ContractInfo    WHERE HTBH= '" + contractNo + "'  ");
            if(null==mainMap){
                continue;
            }
            String fillDate=mainMap.getString("fillDate");
            String ctCode=mainMap.getString("ctCode");
            DBSql.update("UPDATE BO_XR_EPM_A_CONTRACT SET APPLY_NO='"+ctCode+"',APPLY_DATE='"+fillDate+"' WHERE ID='"+id+"'"  );
        }

        List<RowMap> bMaps = DBSql.getMaps("SELECT ID,CONTRACT_NO  FROM BO_XR_SP_B_CONTRACT_SIGN WHERE CONTRACT_NO   in (" +
                "'SHKY(2017)工程02-C002'" +
                        ",'SHKY(2017)工程-C011'" +
                        ",'SHKY(2017)工程-C008'" +
                        ",'SHKY(2018)工程05-F001'" +
                        ",'SHKY(2018)工程02-C004'" +
                        ",'SHKY(2018)工程09-D001'" +
                        ",'SHKY(2017)工程-D003'" +
                        ",'SHKY(2017)工程06-H001'" +
                        ",'SHKY(2017)工程02-F003'" +
                        ",'SHKY(2018)工程-F002'" +
                        ",'SHKY(2018)工程09-F002'" +
                        ",'SHKY(2018)工程-F001'" +
                        ",'SHKY(2018)工程-C004'" +
                        ",'SHKY(2018)工程12-F002'" +
                        ",'SHKY(2018)工程02-D005'" +
                        ",'SHKY(2017)工程02-F005'" +
                        ",'SHKY(2017)工程-C001'" +
                        ",'SHKY(2018)工程02-D007'" +
                        ",'SHKY(2017)工程-F002'" +
                        ",'SHKY(2018)工程07-D001'" +
                        ",'SHKY(2018)工程-F003'" +
                        ",'SHKY(2017)工程-H003'" +
                        ",'SHKY(2018)工程09-D002'" +
                        ",'SHKY(2017)工程02-D004'" +
                        ",'SHKY(2016)工程-C001'" +
                        ",'SHKY(2018)工程02-D001'" +
                        ",'SHKY(2018)工程09-D003'" +
                        ",'SHKY(2018)工程02-C005'" +
                        ",'SHKY(2017)工程05-D001'" +
                        ",'SHKY(2017)工程05-C002'" +
                        ",'SHKY(2018)工程09-C003'" +
                        ",'SHKY(2018)工程12-F001'" +
                        ",'SHKY(2017)工程03-F002'" +
                        ",'SHKY(2017)工程05-C001'" +
                        ",'SHKY(2018)工程09-F001'" +
                        ",'SHKY(2017)工程02-F002'" +
                        ",'SHKY(2017)工程03-D003')  ");

        for(RowMap m:bMaps){
            String contractNo=m.getString("CONTRACT_NO");
            String id=m.getString("ID");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMap("SELECT fillDept,ctCode FROM tb_ContractInfo    WHERE HTBH= '" + contractNo + "'  ");
            if(null==mainMap){
                continue;
            }
            String fillDate=mainMap.getString("fillDate");
            String ctCode=mainMap.getString("ctCode");
            DBSql.update("UPDATE BO_XR_SP_B_CONTRACT_SIGN SET APPLY_DATE='"+fillDate+"' WHERE ID='"+id+"'"  );
        }
        SDK.getLogAPI().consoleInfo("结束处理A.B类合同签订申请日期问题==========");
    }


}
